package com.hq.bus.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hq.bus.domain.Check;
import com.hq.bus.domain.Customer;
import com.hq.bus.domain.Rent;
import com.hq.bus.mapper.CheckMapper;
import com.hq.bus.service.CheckService;
import com.hq.bus.vo.CheckVo;
import com.hq.sys.util.DataGridView;
import com.hq.sys.util.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.weekend.Weekend;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @BelongsPackage: com.hq.bus.service.impl
 * @Author: jiangjunjie
 * @CreateTime: 2024-12-18  15:12
 * @Description: TODO
 * @Version: 1.8
 */
@Service
@Transactional
public class CheckServiceImpl implements CheckService {
    @Autowired
    private CheckMapper checkMapper;
    @Override
    public int addCheck(Check check) {
        return checkMapper.insertSelective(check);
    }

    @Override
    public int updateCheck(Check check) {
        return checkMapper.updateByPrimaryKey(check);
    }

    @Override
    public int deleteCheck(String checkid) {
        return checkMapper.deleteByPrimaryKey(checkid);
    }

    @Override
    public int deleteBatchCheck(String[] checkids) {
            for (String checkid : checkids) {
                checkMapper.deleteByPrimaryKey(checkid);
            }
        return 0;
    }

    @Override
    public DataGridView queryAllCheck(CheckVo checkVo) {
        Page<Object> page = PageHelper.startPage(checkVo.getPage(), checkVo.getLimit());
        // List<Customer> data = this.customerMapper.selectAll();
        Weekend<Check> weekend = Weekend.of(Check.class);
        if (StrUtil.isNotBlank(checkVo.getCheckid())){
            weekend.weekendCriteria().andEqualTo(Check::getCheckid, checkVo.getCheckid());
        }
        if (Objects.nonNull(checkVo.getCreatetime()) && Objects.nonNull(checkVo.getCheckdate())){
            weekend.weekendCriteria().andBetween(Check::getCreatetime, checkVo.getCreatetime(), checkVo.getCheckdate());
        }
        if (StrUtil.isNotBlank(checkVo.getCheckdesc())){
            weekend.weekendCriteria().andLike(Check::getCheckdesc, "%" + checkVo.getCheckdesc() + "%");
        }
       /* if(StrUtil.isNotBlank(checkVo.getAddress())){
            weekend.weekendCriteria().andLike(Check::getAddress, "%" + checkVo.getAddress() + "%");
        }
        if (StrUtil.isNotBlank(checkVo.getPhone())){
            weekend.weekendCriteria().andLike(Check::getPhone, "%" + checkVo.getPhone() + "%");
        }
        if (Objects.nonNull(checkVo.getSex())){
            weekend.weekendCriteria().andEqualTo(Check::getSex, checkVo.getSex());
        }
        if (StrUtil.isNotBlank(checkVo.getCareer())){
            weekend.weekendCriteria().andLike(Check::getCareer, "%" + checkVo.getCareer() + "%");
        }*/
        List<Check> data = checkMapper.selectByExample(weekend);
        return new DataGridView(page.getTotal(), data);
    }

    @Override
    public Check queryCheckById(Check check) {
        return checkMapper.selectByPrimaryKey(check.getCheckid());
    }
}
